﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Minio.AspNetCore;
using System.Net;
using System.Runtime.CompilerServices;
using System.Text;

namespace Common.Framework.Core.Url
{
    /// <summary>
    /// minio
    /// </summary>
    public static   class UrlConfigure
    {

    
        /// <summary>
        /// 配置Minio
        /// </summary>
        /// <param name="services"></param>
        /// <param name="Configuration"></param>
        /// <returns></returns>
        public static  UrlConfig ConfigureUrlConfig()
        {
            IConfiguration _configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build(); ;
            UrlConfig config =new UrlConfig();
            config.UserUrl = _configuration.GetSection("UrlConfig:UserUrl").Value;
            return config;
        }
        /// <summary>
        /// 根据url获取数据
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static async Task<string> Get(string url)
        {

            System.Net.HttpWebRequest request;
            request = (System.Net.HttpWebRequest)WebRequest.Create(url);
            request.Method = "get";
            request.ContentType = "application/json;charset=UTF-8";
            System.Net.HttpWebResponse response;
            response = (System.Net.HttpWebResponse)request.GetResponse();
            System.IO.Stream s;
            s = response.GetResponseStream();
            string StrDate = "";
            string strValue = "";
            StreamReader Reader = new StreamReader(s, Encoding.UTF8);
            while ((StrDate = Reader.ReadLine()) != null)
            {
                strValue += StrDate;
            }
            return strValue;
        }

    }
}
